package com.boang.factory;

import com.boang.exception.StorageException;
import com.boang.service.CloudStorageService;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author 13813
 */
@Component
public class StorageServiceFactory {

    private final Map<String, CloudStorageService> storageServices;

    public StorageServiceFactory(
            Map<String, CloudStorageService> services) {
        this.storageServices = services;
    }

    public CloudStorageService getService(String type) {
        return storageServices.get(type + "ServiceImpl");
    }

    public CloudStorageService getActiveService() throws StorageException {
        return storageServices.values().stream()
                .findFirst()
                .orElseThrow(() -> new StorageException("No active storage service"));
    }
}